/**
////////////////////////////////////////////////////////////////////////////////
//                                                                            // 
//  Copyright (c) 2013 Santiago Benito Rebollo. Eclipse Public License - v 1.0//
//  @author Santiago Benito Rebollo.                                          // 
//  santiago.benito.rebollo@gmail.com                                         //
//                                                                            //  
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC// 
// LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM//
// CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.                      //
//                                                                            //
// A Contributor may choose to distribute the Program in object code form     //
// under its own license agreement, provided that:                            //
//                                                                            //
// a) it complies with the terms and conditions of this Agreement; and        //
// b) its license agreement:                                                  //
//                                                                            //
// i) effectively disclaims on behalf of all Contributors all warranties and  //
// conditions, express and implied, including warranties or conditions of     //  
// title and non-infringement, and implied warranties or conditions of        //
// merchantability and fitness for a particular purpose;                      //
// ii) effectively excludes on behalf of all Contributors all liability for   //
// damages, including direct, indirect, special, incidental and consequential //
// damages, such as lost profits;                                             //
// iii) states that any provisions which differ from this Agreement are       //
// offered by that Contributor alone and not by any other party; and          //
// iv) states that source code for the Program is available from such         //
// Contributor, and informs licensees how to obtain it in a reasonable        //
// manner on or through a medium customarily used for software exchange.      //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
 */

package com.chago.fastrecado;

import java.util.Calendar;
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException ;
//import isf.util.log.AbstractStreamLog;
//import isf.util.PropertiesLoader;

/**
* Specifies exceptions of any business rule process on the FastRecado project. 
* This class is defined in the same way that its parent class. We have defined it 
* just for avoiding dependence with its parent on the whole application. 
* <p>Every time an instance (except when using the default constructor) 
* of this class is created, it informs to the log file.</p>
*
* @author <a href="mailto:santiago.benito.rebollo@gmail.com">Santiago Benito Rebollo </a>
* @version 1.0
* @see FastRecadoException
* @since 2013
*/
public class StandardLog {

	private PrintStream ps = null;
	private boolean booEnableTraces = true;
	
	/**
	*	Constructor: Initializes output printer.
	*/
	public StandardLog() throws FileNotFoundException {
	
		//read the traces value from the properties in the future. This first version must be recompiled every
		//time you want to change value
		
		
		ps =new PrintStream(
				new FileOutputStream("D:/Java/workspace/fastrecado2013/traces.log"));
		// To avoid to classes write messages at the same time
		synchronized(this)
		{
			
			println("-------------------------------------------------------");
			println("StandardLog log initialized: " );
			println("-------------------------------------------------------");
		}
	}

	
	
	/**
	* This method print in the FileOutputStream the message
	* @param String with the message
	* @post $none
	 */
	private void println (String strMessage) {

		if (booEnableTraces) {
			Calendar c1 = Calendar.getInstance();
			String strDate = "["+c1.get(Calendar.DATE)+"-"
							+c1.get(Calendar.MONTH)+"-"
							+c1.get(Calendar.YEAR)+" time:("
							+c1.get(Calendar.HOUR_OF_DAY)+":"
							+c1.get(Calendar.MINUTE)+"."
							+c1.get(Calendar.SECOND)+")"
							+"]";
			ps.println(strDate+" "+strMessage);
		}
	}

	/**
	* This method show the trace in the log in traces are enabled
	* @param String with the message of the trace 
	* @post $none
	 */
	public void trace (String strMessage) {

		if (booEnableTraces) {
			Calendar c1 = Calendar.getInstance();
			String strDate = "["+c1.get(Calendar.DATE)+"-"
							+c1.get(Calendar.MONTH)+"-"
							+c1.get(Calendar.YEAR)+" time:("
							+c1.get(Calendar.HOUR_OF_DAY)+":"
							+c1.get(Calendar.MINUTE)+"."
							+c1.get(Calendar.SECOND)+")"
							+"]";
			ps.println(strDate+" [TRAZE] "+strMessage);
		}
	}	
	
	/**
	* This method print the error message in the log 
	* @param String with the message
	* @post $none
	 */
	public void error (String strMessage) {

		if (booEnableTraces) {
			Calendar c1 = Calendar.getInstance();
			String strDate = "["+c1.get(Calendar.DATE)+"-"
							+c1.get(Calendar.MONTH)+"-"
							+c1.get(Calendar.YEAR)+" time:("
							+c1.get(Calendar.HOUR_OF_DAY)+":"
							+c1.get(Calendar.MINUTE)+"."
							+c1.get(Calendar.SECOND)+")"
							+"]";
			ps.println(strDate+" [ERROR] "+strMessage);
		}
	}	
	
}
